package com.nbsaas.boot.product.rest.convert;

import com.nbsaas.boot.product.data.entity.Product;
import com.nbsaas.boot.product.api.domain.response.ProductResponse;

import com.nbsaas.boot.utils.BeanDataUtils;
import com.nbsaas.boot.rest.api.Converter;
/**
* 商品-实体对象转化成响应对象
*/

public class ProductResponseConvert  implements Converter<ProductResponse,Product> {

    @Override
    public ProductResponse convert(Product source) {
        ProductResponse  result = new  ProductResponse();
        BeanDataUtils.copyProperties(source, result);

                    try {
                        if(source.getProductCatalog()!=null){
                            result.setProductCatalogName(source.getProductCatalog().getName());
                        }
                    } catch (Exception ignored) { }

                    if(source.getProductCatalog()!=null){
                        result.setProductCatalog(source.getProductCatalog().getId());
                    }

                    try {
                        if(source.getUnit()!=null){
                            result.setUnitName(source.getUnit().getName());
                        }
                    } catch (Exception ignored) { }

                    if(source.getUnit()!=null){
                        result.setUnit(source.getUnit().getId());
                    }
        return result;
    }

}

